﻿namespace SAD.DataCenter
{
    using System;
    using System.Collections.Generic;
    using SAD.Common.Models;

    internal class ShowNodeManager
    {
        private object m_syncObject = new object();
        private List<ShowNode_Data> m_ShowClientsByCreateOrder = new List<ShowNode_Data>();
        private Dictionary<string, ShowNode_Data> m_ShowClientsByID = new Dictionary<string, ShowNode_Data>();

        internal void Register(ShowNode_Data info)
        {
            lock (m_syncObject)
            {
                m_ShowClientsByCreateOrder.Add(info);
                m_ShowClientsByID.Add(info.ID, info);
            }
        }

        internal void Unregister(ShowNode_Data info)
        {
            lock (m_syncObject)
            {
                m_ShowClientsByCreateOrder.Remove(info);
                m_ShowClientsByID.Remove(info.ID);
            }
        }

        internal ShowNode_Data GetClientInfo(string clientID)
        {
            return m_ShowClientsByID[clientID];
        }

        internal ShowNode_Data[] GetClientInfos()
        {
            return m_ShowClientsByCreateOrder.ToArray();
        }

        internal ShowNode_Data this[int index]
        {
            get
            {
                return m_ShowClientsByCreateOrder[index];
            }
        }
    }
}
